package cn.slipi.admin.common.utils;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @author litao
 */
public class RandomUtil {
    private static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current();
    private static char[] codeSequence = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};

    public static String getRandomNum(Integer codeCount) {
        // randomCode记录随机产生的验证码
        StringBuilder randomCode = new StringBuilder();
        // 随机产生codeCount个字符的验证码。
        for (int i = 0; i < codeCount; i++) {
            String strRand = String.valueOf(codeSequence[RANDOM.nextInt(codeSequence.length)]);
            // 将产生的四个随机数组合在一起。
            randomCode.append(strRand);
        }
        return randomCode.toString();
    }
}
